$(document).ready(function(){
	if(isLogin()){
		//调用加载菜单的函数
		addMenu();
		
	}
});

//登录的验证
function isLogin(){
	var info=sessionStorage.getItem("user");
	if(info==null){
		alert("请先登录");
		window.location.href="login.html";
		return false;
	}else{
		var obj=JSON.parse(info);
		$("#lgUser").html(obj.nickName);
		return true;
	}
}
//加载菜单的函数
function addMenu(){
	$.ajax({
		url:totalPath.menu,
		type:"get",
		dataType:"json",
		success:function(rs){
			$.each(rs,function(i,n){
				$("<a/>").addClass("btn btn-danger btn-block")
						 .attr("data-toggle","collapse")
						 .attr("data-target","#m"+i)
						 .attr("aria-controls","m"+i)
						 .html(n.title)
						 .appendTo("#menu");
				 $("<div/>").addClass("collapse")
							.attr("id","m"+i)
							.appendTo("#menu");
				//添加一个二级菜单
				$.each(n.list,function(j,m){
					$("<a/>").addClass("btn btn-success btn-block")
							 .html(m.title)
							 .attr("href",m.path)
							 .attr("target","ifrm")
							 .appendTo("#m"+i)
				});

						 
			});
		}
	});
	
}